<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<jsp:include page="/all/base.jsp" />
<html>
<head>
<script type="text/javascript"
	src="${contextPath}/js/field_formatter.js"></script>
<title>用户组管理</title>

<script type="text/javascript"><!--
    var dataGrid = null;
    var suWindow = null;
    var columns = [[{field: 'id', title: 'ID', hidden: true},
        	    	{field: 'authority', title: '名称', width: 100},
        	    	{field: 'nickname', title: '显示名称', width: 100},
        	    	{field: 'level', title: '用户组级别', formatter: levelFormatter, width: 100},
        	    	{field: 'updateTime', title: '更新时间', formatter: updateTimeFormatter, width: 100}]];
   	var param = {
   		id: "maingrid",
		url: m_role_find_url,
		deleteUrl: m_role_delete_url,
		width: 'auto',
		height: 'auto',
		fitColumns: true,
		nowrap:false,
		rownumbers:true,
		columns:columns,
		singleSelect:true,
		onDblClickRow:function(rowIndex, rowData) {
			f_modify();
		},
		onRowsSelectedBindButtons:[{id:'modifyBtn', isEnable:function(rows){
				return rows.length == 1;
			}
		}, {id:'deleteBtn', isEnable:function(rows){
				var count = rows.length;
				if (count > 0) {
					for (var i = 0; i < count; i++) {
						if (rows[i].level == -1) {
							return false;
						}
					}
					return true;
				} else {
					return false;
				}
			}
		}]
	};
	var windowParm = {
		id:"win",
		width:600,
	    height:400,
	    modal:true,
	    closed:true,
	    minimizable:false,
	    maximizable:false,
	    iconCls:"icon-save",
	    onClose:function() {
	    }
	};
	$(function () {
		dataGrid = new optimus.DataGrid(param);
		suWindow = new optimus.Window(windowParm);
	});

	function f_add() {
		suWindow.open("添加用户组", role_edit_page);
	}
	
	function f_modify() {
		var item = dataGrid.getSelectedRow();
		var url = role_edit_page + '?id=' + item.id;
		suWindow.open("修改用户组", url);
	}
	
	function onSubmitChangeSuccess() {
		f_reload();
		suWindow.close();
	}

	function f_delete() {
		dataGrid.deleteSelectedRows();
		// 此函数可以作为参数传入deleteSelectRows
		/*function(rows){
			var ids = [];
			for (var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
			return ids.join(',');
		}*/
	}

	function f_reload() {
		dataGrid.reload();
	}
--></script>
</head>
<body style="padding: 10px">
<div style="margin-bottom:20px;">
<a href="#" id="addBtn" class="easyui-linkbutton" onclick="f_add()">添加</a>
<a href="#" id="modifyBtn" class="easyui-linkbutton" onclick="f_modify()">修改</a>
<a href="#" id="deleteBtn" class="easyui-linkbutton" onclick="f_delete()">删除</a>
<a href="#" id="reloadBtn" class="easyui-linkbutton" onclick="f_reload()">刷新</a>
</div>
<div id="maingrid" style="margin-top: 20px"></div>
<div id="win"></div>
</body>
</html>